package com.zdy.worldtion.base;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

import com.zdy.worldtion.utils.DialogUtil;

import androidx.fragment.app.Fragment;


/**
 * Created by wxl
 * 基于Rx的Presenter封装,控制订阅的生命周期
 */

public class RxBasePresenter<T extends BaseView> implements BasePresenter<T> {

    public T mView;
    protected RxManage mRxManage = new RxManage();
    public Dialog loadingDialog;

    @Override
    public void attachView(T view) {
        if (view instanceof Fragment) {
            loadingDialog = DialogUtil.showLoadingDialog((Context) ((Fragment) view).getActivity());
        } else if (view instanceof Activity) {
            loadingDialog = DialogUtil.showLoadingDialog((Context) view);
        }
        this.mView = view;
    }

    @Override
    public void detachView() {
        mRxManage.clear();
    }
}
